Ext.define('qjtravel.view.ProductDetail', {
    extend: 'Ext.Panel',
    xtype: 'ProductDetail',
   // singleton:true,
    requires: [
        'Ext.List', 'Ext.TitleBar',
        'Ext.form.Panel',
        'Ext.Label',
        'Ext.form.FieldSet'
    ],
    config: {
        gotourl:"",
        layout: 'vbox',
        scrollable: {
            direction: 'vertical',
            directionLock: true
        },
        items: [
            {
                xtype: 'toolbar',
                id: 'toolbars',
                ui: 'dark',
                docked: 'top',
                items: [
                    {
                        xtype: 'button',
                        id: 'backs',
                        text: '返回',
                        listeners: {
                            tap: function () {
                                window.localStorage.removeItem("controllerClick");
                                window.localStorage.removeItem("homeCarClick");
                                window.localStorage.removeItem("productClick");

                                Ext.getCmp("toolbars").setTitle("");
                                var contentH=Ext.getCmp("detailCarousel").getHeight();
                                Ext.getCmp("detailCarousel").setHtml("")
                                Ext.getCmp("detailCarousel").setHeight(contentH+"px")
                                var backid = Ext.Viewport.getInnerItems().length
                                Ext.Viewport.remove(this.up('ProductDetail'), true);
                                Ext.Viewport.setActiveItem(backid - 2);
                            }
                        }
                    },
                    {xtype: 'spacer'},
                    {
                        xtype: 'button',
                        align: 'right',
                        iconCls: 'action',
                        // text: '分享',
                        handler: function () {
                            var picurl = Ext.getCmp('picurl').getValue();
                            var explain = Ext.getCmp('explain').getValue();
                            if (explain.length > 130) {
                                explain=explain.replace(/<p>/g,'');
                                explain=explain.replace(/&nbsp;/g,'');
                                explain = explain.substr(0, 130) + '......';
                            }
                            cordova.exec(function (winParam) {
                                },
                                function (error) {
                                },
                                "Share",
                                "share",
                                [explain, picurl,'http://xayoudao.com/qujianglvyou/']);
                            return;
                        }
                    },
                    {
                        xtype: 'button',
                        align: 'right',
                        iconCls: 'favorites',
                        // text: '收藏',
                        handler: function () {
                            var collect = Ext.getStore('Collect').load();
                            var cpid = localStorage.getItem('cpid');
                            var name = Ext.getCmp('name').getValue();

                            var isF = collect.find('cpid', cpid)
                            if (isF == -1) {
                                collect.add({
                                    cpid: cpid,
                                    name: name
                                });
                                collect.sync();
                                cordova.exec(function (message) {
                                }, function (error) {
                                }, "Messages", "showMsg", ['收藏成功！']);
                                return false;
                            } else {
                                cordova.exec(function (message) {
                                }, function (error) {
                                }, "Messages", "showMsg", ['收藏过了！']);
                                return false;
                            }
                        }
                    }
                ]
            },
            {
                xtype: 'carousel',
                store: 'ProductDetail',
                style: 'margin:10px;',
                id: 'detailCarousel',
                listeners: {
                    initialize: function (carousel) {
                        var h=document.body.clientHeight-90;
                        carousel.setHeight(h*0.55)
                    }
                }
            },
            {
                xtype: 'label',
                style: 'margin:0 10px;',
                cls: 'font2 blod detail_title color1',
                tpl: "{name}"
            },
            {
                xtype: 'fieldset',
                id: 'fieldset',
                items: [
                    {
                        html: '',
                        cls: 'font1 color1 more_form1 more_border',
                        id: 'tel',
                        listeners: {
                            painted: function (label) {
                                label.on('tap', function () {
                                    var args = Ext.getCmp('callNumber').getValue();
                                    cordova.exec(function (successCallback) {
                                    }, function (errorCallback) {
                                    }, "Redirect", "callNumber", [args]);
                                    return false;
                                }, this)
                            }
                        }
                    },
                    {
                        html: '',
                        cls: 'font1 color1 more_form1',
                        id: 'address',
                        listeners: {
                            painted: function (label) {
                                label.on('tap', function () {
                                    var popmap = Ext.create('qjtravel.view.PopMap')
                                    Ext.Viewport.animateActiveItem(popmap, {type: 'slide', direction: 'left'});
                                    popmap.search(Ext.getCmp('name').getValue());
                                    return false;
                                }, this)
                            }
                        }
                    },{
                        html: '去携程网预订',
                        id:"gotoXC",
                        cls: 'font1 color1 more_form1 more_border_top',
                        listeners: {
                            painted: function (label) {
                                label.on('tap', function () {
                                    //window.open(Ext.getCmp("gotoXCUrl").getValue());
                                    window.open(Ext.getCmp("gotoXCUrl").getValue(), '_blank', 'location=no');
                                    return false;
                                }, this)
                            }
                        }
                    }
                ]
            },
            {
                xtype: 'label',
                style: 'margin:0 10px;',
                cls: 'content',
                tpl: "{explain}"
            },
            {
                xtype: 'textfield',
                id: 'callNumber', 
                hidden: true
            },
            {
                xtype: 'textfield',
                id: 'name',
                tpl: "{name}",
                hidden: true
            },
            {
                xtype: 'textfield',
                id: 'explain',
                tpl: "{explain}",
                hidden: true
            },
            {
                xtype: 'textfield',
                id: 'picurl',
                tpl: "{picurl}",
                hidden: true
            },{
                xtype: 'hiddenfield',
                id: 'gotoXCUrl',
                hidden: true
            }
        ],
        listeners: {
            painted: function () {
                Ext.Viewport.unmask();
            },
            back:function() {
                window.localStorage.removeItem("controllerClick");
                window.localStorage.removeItem("homeCarClick");
                window.localStorage.removeItem("productClick");
                var backid = Ext.Viewport.getInnerItems().length
                Ext.Viewport.remove(Ext.Viewport.getActiveItem(), true);
                Ext.Viewport.setActiveItem(backid - 2);
            }
        }
    }
});
